package com.runfast.waimai.service.impl;

import com.runfast.common.service.BaseService;
import com.runfast.waimai.dao.mapper.BasePurviewMapper;
import com.runfast.waimai.dao.mapper.WaiMaiRunfastDeliverCostMapper;
import com.runfast.waimai.dao.model.WaiMaiRunfastDeliverCost;
import com.runfast.waimai.dao.model.WaiMaiRunfastDeliverCostExample;
import com.runfast.waimai.service.WaiMaiRunfastDeliverCostService;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class WaiMaiRunfastDeliverCostServiceImpl extends BaseService<WaiMaiRunfastDeliverCost, Integer, WaiMaiRunfastDeliverCostExample> implements WaiMaiRunfastDeliverCostService {
    public Integer updateByPrimaryKeyWithBLOBs(WaiMaiRunfastDeliverCost deliverCost){
        WaiMaiRunfastDeliverCostMapper waiMaiRunfastDeliverCostMapper=(WaiMaiRunfastDeliverCostMapper)this.mapper;
        return waiMaiRunfastDeliverCostMapper.updateByPrimaryKeyWithBLOBs(deliverCost);
    }


    public void saveFor(WaiMaiRunfastDeliverCost t){
        mapper.insertSelective(t);
        if(t!=null&&t.getIsdefault()!=null&&t.getIsdefault()==1){
            WaiMaiRunfastDeliverCostExample example=new WaiMaiRunfastDeliverCostExample();
            example.createCriteria().andAgentidEqualTo(t.getAgentid());
            List<WaiMaiRunfastDeliverCost> olds=mapper.selectByExample(example);
            if(olds!=null&&olds.size()>0){
                for(WaiMaiRunfastDeliverCost old:olds){
                    if(old!=null&&!old.getId().equals(t.getId())){
                        old.setIsdefault(0);
                        mapper.updateByPrimaryKeySelective(old);
                    }

                }
            }
        }
    }

    public void updateFor(WaiMaiRunfastDeliverCost t){
        mapper.updateByPrimaryKeySelective(t);
        if(t!=null&&t.getIsdefault()!=null&&t.getIsdefault()==1){
            WaiMaiRunfastDeliverCostExample example=new WaiMaiRunfastDeliverCostExample();
            example.createCriteria().andAgentidEqualTo(t.getAgentid());
            List<WaiMaiRunfastDeliverCost> olds=mapper.selectByExample(example);
            if(olds!=null&&olds.size()>0){
                for(WaiMaiRunfastDeliverCost old:olds){
                    if(old!=null){
                        if(!old.getId().equals(t.getId())){
                            old.setIsdefault(0);
                        }
                    }
                    mapper.updateByPrimaryKeySelective(old);
                }
            }
        }

    }
}